﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Sonce.Controls
{
    public partial class MenuSeparator : Control
    {
        #region Constructor
        public MenuSeparator()
            : base()
        {
            this.DefaultStyleKey = typeof(MenuSeparator);
            this.Layout = Orientation.Vertical;
        }
        #endregion

        #region Properties
        public Orientation Layout
        {
            get
            {
                return (Orientation)GetValue(LayoutProperty);
            }
            set
            {
                SetValue(LayoutProperty, value);
                if (this.VerticalLine != null && this.HorizontalLine != null)
                {
                    this.VerticalLine.Visibility = (value == Orientation.Horizontal ? Visibility.Visible : Visibility.Collapsed);
                    this.HorizontalLine.Visibility = (value == Orientation.Horizontal ? Visibility.Collapsed : Visibility.Visible);
                }
            }
        }
        #endregion

        #region Dependency
        public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register("Layout", typeof(Orientation), typeof(MenuSeparator), new PropertyMetadata(null));
        #endregion

        #region Template
        protected FrameworkElement RootElement;
        protected FrameworkElement VerticalLine;
        protected FrameworkElement HorizontalLine;

        public override void OnApplyTemplate()
        {
            RootElement = (FrameworkElement)GetTemplateChild("RootElement");
            VerticalLine = (FrameworkElement)GetTemplateChild("VerticalLine");
            HorizontalLine = (FrameworkElement)GetTemplateChild("HorizontalLine");
            this.Layout = this.Layout;
        }
        #endregion
    }
}
